Gradient Decent Method¶

\begin{equation} f(x) = 2 x^2 + 3 \end{equation} とする.

In [ ]:
def f(x):
    return 2 * x**2 + 3

a).
$-1 \leq x \leq 1$の範囲から,ランダムに1000個の点を選び,その集合を$X$とする.
$X$の各点について$f(x)$を計算せよ.
また,その点$(x, f(x))$をプロットせよ.

Out[ ]:
<matplotlib.collections.PathCollection at 0x7ffa06d43460>
No description has been provided for this image

b).
$ -10 \leq x \leq 10$を満たす点$a, b$を選び,$g(x; a, b) = a x^2 + b$をプロットせよ.

a = -9.095812846654642 b = -4.783305037090429
No description has been provided for this image

c).
a)で選んだ点について,$(x, g(x))$を計算し,$l(a, b) = \frac{1}{2000} \sum_{x \in X} (f(x) - g(x))^2$を計算せよ.

Out[ ]:
71.9627660572912

d). Gradient Decent Method
$$ a' = a - \eta \frac{\partial l}{\partial a} $$ $$ b' = b - \eta \frac{\partial l}{\partial b} $$ を実装し,得られた$l$を最小とする$(a, b)$を用いて,$g(x; a, b)$をプロットせよ.
また,$(x, f(x))$と比較せよ.

a_optim = 1.997610812059878 b_optim = 3.000876112358275
No description has been provided for this image
No description has been provided for this image